package com.labofjet.util;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import com.labofjet.jpa.bean.NativeSQLRepository;

/**
 * 系统参数工具类,主要用于获取各种文件配置的参数和数据库里配置的参数 注意,使用的时候直接注入这个bean,而不是调用静态的方法
 * 
 * @author jyzjyz12@163.com
 * 
 */
@Component
public class XtcsUtils implements EnvironmentAware {

	private static final String XTCS_QUERY = "select csz from xtcs where csdm = :csdm";

	private Environment env;

	@Resource
	private NativeSQLRepository nativeSQLRepository;

	@Override
	public void setEnvironment(Environment environment) {
		env = environment;
	}

	/**
	 * 获取配置在properties中的参数
	 * 
	 * @param name
	 * @return
	 */
	public String getProperties(String name) {
		return env.getProperty(name);
	}

	/**
	 * 返回数据库中的系统参数
	 * 
	 * @param name
	 * @return
	 */
	public String getXtcs(String csdm) {
		Map<String, Object> map = new HashMap<>();
		map.put("csdm", csdm);
		return (String) nativeSQLRepository.querySingle(XTCS_QUERY, map);
	}
}
